package com.gt.common;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class StringToJson {

    public static JsonNode convertStringToJson(String jsonString) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.readTree(jsonString);
        } catch (Exception e) {
            throw new RuntimeException("字符串转化为json失败", e);
        }
    }

    public static String convertJsonToString(JsonNode json) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.writeValueAsString(json);
        } catch (Exception e) {
            throw new RuntimeException("json转化为字符串失败", e);
        }
    }
}
